import { createStore } from "redux";

const initState = {
  count: 0,
  msg: "消息",
  info: "用户说明",
};
function reducer(state=initState,action) {
   
   
    switch (action.type) {
        case 'add':
            return {...state,count:state.count+1};
        case 'sub':
            return {...state,count:state.count-1};
        default:
            return state;
    }
}

const store = createStore(reducer)

// 监听数据变化
store.subscribe(() => {
    console.log('数据发生变化',store.getState());
})


store.dispatch({ type: "add" });
// console.log(store.getState())
store.dispatch({ type: "sub" });
// console.log(store.getState())